home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2011 November
/
CHIP_2011_11.iso
/
Programy
/
Inne
/
Gry
/
Carnage_Contest
/
scripts
/
CC Original
/
weapons
/
Chainsaw Launcher.lua
< prev
next >
Wrap
Text File
|
2010-09-22
|
7KB
|
185 lines
--------------------------------------------------------------------------------
-- Weapon Chainsaw Launcher + Projectile Chainsaw
-- Original Carnage Contest Weapon
-- Script by DC, August 2009, www.UnrealSoftware.de
--------------------------------------------------------------------------------
-- Setup Tables
if cc==nil then cc={} end
cc.chainsawlauncher={}
cc.chainsawlauncher.chainsaw={}
-- Load & Prepare Ressources
cc.chainsawlauncher.gfx_wpn=loadgfx("weapons/launcher.bmp") -- Weapon Image
setmidhandle(cc.chainsawlauncher.gfx_wpn)
cc.chainsawlauncher.gfx_pro0=loadgfx("weapons/chainsaw0.bmp") -- Projectile Image
setmidhandle(cc.chainsawlauncher.gfx_pro0)
cc.chainsawlauncher.gfx_pro1=loadgfx("weapons/chainsaw1.bmp") -- Projectile Image
setmidhandle(cc.chainsawlauncher.gfx_pro1)
cc.chainsawlauncher.sfx_attack=loadsfx("chainsawlaunch.wav") -- Attack Sound
cc.chainsawlauncher.sfx_cut=loadsfx("sawcut.ogg") -- Cut Sound
--------------------------------------------------------------------------------
-- Weapon: Chainsaw Launcher
--------------------------------------------------------------------------------
cc.chainsawlauncher.id=addweapon("cc.chainsawlauncher","Chainsaw Launcher",cc.chainsawlauncher.gfx_pro0,0,2) -- Add Weapon (0 uses, first in round 2)
cc.chainsawlauncher.ammo=3 -- 3 Shots
function cc.chainsawlauncher.draw() -- Draw
setblend(blend_alpha)
setalpha(1)
setcolor(255,90,100)
drawinhand(cc.chainsawlauncher.gfx_wpn,6,0)
-- HUD ammobar
if cc.chainsawlauncher.ammo-weapon_shots>0 then
hudammobar(cc.chainsawlauncher.ammo-weapon_shots,cc.chainsawlauncher.ammo)
end
-- HUD Crosshair
if cc.chainsawlauncher.ammo-weapon_shots>0 then
hudcrosshair(6,3)
end
end
function cc.chainsawlauncher.attack(attack) -- Attack
-- Decrement timer
if weapon_timer>0 then
weapon_timer=weapon_timer-1
end
-- Attack
if weapon_shots<cc.chainsawlauncher.ammo and weapon_timer<=0 and attack==1 then
-- No more weapon switching!
useweapon(0)
weapon_timer=25
playsound(cc.chainsawlauncher.sfx_attack)
weapon_shots=weapon_shots+1
id=createprojectile(cc.chainsawlauncher.chainsaw.id)
projectiles[id]={}
-- Ignore collision with current player at beginning
projectiles[id].ignore=playercurrent()
-- Set initial position of projectile
projectiles[id].x=getplayerx(0)+(6*getplayerdirection(0))+math.sin(math.rad(getplayerrotation(0)))*10.0
projectiles[id].y=getplayery(0)+3-math.cos(math.rad(getplayerrotation(0)))*10.0
-- Animation
projectiles[id].frame=0
projectiles[id].frametimer=0
-- Timer
projectiles[id].timer=0
-- Initial movement
projectiles[id].sx=math.sin(math.rad(getplayerrotation(0)))*20
projectiles[id].sy=-math.cos(math.rad(getplayerrotation(0)))*20
projectiles[id].x=projectiles[id].x-projectiles[id].sx
projectiles[id].y=projectiles[id].y-projectiles[id].sy
cc.chainsawlauncher.chainsaw.move(id,0)
-- Set speed of projectile
projectiles[id].sx=math.sin(math.rad(getplayerrotation(0)))*7.0
projectiles[id].sy=-math.cos(math.rad(getplayerrotation(0)))*7.0
-- Effects
recoil(5)
-- End Turn
if (weapon_shots>=cc.chainsawlauncher.ammo) then
endturn()
end
end
end
--------------------------------------------------------------------------------
-- Projectile: Chainsaw
--------------------------------------------------------------------------------
cc.chainsawlauncher.chainsaw.id=addprojectile("cc.chainsawlauncher.chainsaw") -- Add Projectile
function cc.chainsawlauncher.chainsaw.draw(id) -- Draw
-- Setup draw mode
setblend(blend_alpha)
setalpha(1)
setcolor(255,255,255)
setscale(1,1)
-- Calculate projectile rotation
setrotation(math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy)))
-- Draw projectile
projectiles[id].frametimer=projectiles[id].frametimer+1
if projectiles[id].frametimer>5 then
projectiles[id].frametimer=0
projectiles[id].frame=1-projectiles[id].frame
end
if projectiles[id].frame==0 then
drawimage(cc.chainsawlauncher.gfx_pro0,projectiles[id].x,projectiles[id].y)
else
drawimage(cc.chainsawlauncher.gfx_pro1,projectiles[id].x,projectiles[id].y)
end
-- Draw Arrow if out of Screen
outofscreenarrow(projectiles[id].x,projectiles[id].y)
end
function cc.chainsawlauncher.chainsaw.update(id) -- Update
-- Move
cc.chainsawlauncher.chainsaw.move(id,1)
end
function cc.chainsawlauncher.chainsaw.move(id,fx)
rot=math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy))
-- Particle Tail
if (fx==1) then
particle(p_smoke,projectiles[id].x-math.sin(math.rad(rot))*7,projectiles[id].y+math.cos(math.rad(rot))*7)
particlespeed(math.random(-2,2)*0.1,math.random(-2,2)*0.1)
particlefadealpha(0.01)
end
-- Wind + Gravity influence on speed
projectiles[id].sx=projectiles[id].sx+getwind()*0.3
projectiles[id].sy=projectiles[id].sy+getgravity()*1.5
-- Move (in substep loop for optimal collision precision)
msubt=math.ceil(math.max(math.abs(projectiles[id].sx),math.abs(projectiles[id].sy))/5)
msubx=projectiles[id].sx/msubt
msuby=projectiles[id].sy/msubt
for i=1,msubt,1 do
projectiles[id].x=projectiles[id].x+msubx
projectiles[id].y=projectiles[id].y+msuby
-- Collision
if collision(col5x5,projectiles[id].x+math.sin(math.rad(rot))*3,projectiles[id].y-math.cos(math.rad(rot))*3)==1 then
if terraincollision()==1 or objectcollision()>0 or playercollision()~=projectiles[id].ignore then
playsound(cc.chainsawlauncher.sfx_cut)
-- Cause Player damage
if playercollision()~=0 and fx==1 then
playerdamage(playercollision(),10)
blood(getplayerx(playercollision()),getplayery(playercollision()))
end
-- Cause Object damage
if objectcollision()>0 and fx==1 then
objectdamage(objectcollision(),10)
projectiles[id].timer=25
end
-- Destroy terrain
terrainexplosion(projectiles[id].x,projectiles[id].y,12,2)
-- Timer / Free
projectiles[id].timer=projectiles[id].timer+1
if projectiles[id].timer>=25 then
-- Explode
arealdamage(projectiles[id].x,projectiles[id].y,30,15)
terrainexplosion(projectiles[id].x,projectiles[id].y,20,1)
-- Crater
grey=math.random(0,40)
if math.random(0,1)==1 then
terrainalphaimage(gfx_crater100,projectiles[id].x,projectiles[id].y,math.random(6,9)*0.1,grey,grey,grey)
else
terrainalphaimage(gfx_crater125,projectiles[id].x,projectiles[id].y,math.random(6,9)*0.1,grey,grey,grey)
end
-- Free
freeprojectile(id)
break
end
end
elseif (fx==1) then
projectiles[id].ignore=0
end
-- Water
if (projectiles[id].y)>getwatery()+5 then
-- Effects
particle(p_waterhit,projectiles[id].x,projectiles[id].y)
playsound(sfx_hitwater1)
-- Free projectile
freeprojectile(id)
break
end
end
end